package com.upsuns.pbio;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;

import com.upsuns.util.IOUtil;
import com.upsuns.util.QueryHandler;

/**
 *@Description:<p>服务器端处理器</p>
 *@author 王旭
 *@time 2016年3月17日 上午9:19:00
 */
public class TimeServerHandler implements Runnable {
	
	private Socket socket;
	
	public TimeServerHandler(Socket socket) {
		this.socket = socket;
	}

	@Override
	public void run() {
		InputStream in = null;
		OutputStream out = null;
		BufferedReader br = null;
		PrintWriter pw = null;
		
		try {
			in = socket.getInputStream();
			out = socket.getOutputStream();
			br = new BufferedReader(new InputStreamReader(in));
			pw = new PrintWriter(out, true);
			
			String resp = QueryHandler.handleQuery(br.readLine());
			
			pw.println(resp);
			
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			IOUtil.close(pw, br, out, in);
		}
		
		
	}
	

}
